// export function debounce(fn, d) {
//   // 记录上一次的延时器
//   let timer = null;
//   let delay = d || 200;
//   return function () {
//     // eslint-disable-next-line prefer-rest-params
//     let args = arguments;
//     let that = this;
//     // 清除上一次延时器
//     clearTimeout(timer);
//     timer = setTimeout(function () {
//       fn.apply(that, args);
//     }, delay);
//   };
// }

export function debounce(fn, d) {
  // 记录上一次的延时器
  let timer = null;
  let delay = d || 200;
  let isIng = false;
  return function () {
    // eslint-disable-next-line prefer-rest-params
    let args = arguments;
    let that = this;
    if (!isIng) {
      isIng = true;
      fn.apply(that, args);
      timer = setTimeout(function () {
        isIng = false;
      }, delay);
    }
  };
}
